package cn.fintecher.pangolin.service.business.service;

import cn.fintecher.pangolin.entity.elastic.CaseTransferLog;
import cn.fintecher.pangolin.service.business.repository.elasticsearch.CaseTransferLogRepository;
import org.apache.commons.collections4.IterableUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: xiaqun
 * @Description:
 * @Date: 9:28 2019/9/25
 */

@Service("caseTransferLogService")
public class CaseTransferLogService {
    @Autowired
    private CaseTransferLogRepository caseTransferLogRepository;

    /**
     * 查询流转记录
     */
    public List<CaseTransferLog> getAllCaseTransferLog(String caseId) {
        BoolQueryBuilder builder = new BoolQueryBuilder();
        builder.must(QueryBuilders.matchPhraseQuery("caseId.keyword", caseId));
        Iterable<CaseTransferLog> iterable = caseTransferLogRepository.search(builder);
        List<CaseTransferLog> list = IterableUtils.toList(iterable);
        list.sort((e1, e2) -> e2.getOperatorTime().compareTo(e1.getOperatorTime()));
        return list;
    }
}
